[HVM] [SMBIOS] Duplicate UUID into serial number in SMBIOS tables.
authorkaf24@localhost.localdomain <kaf24@localhost.localdomain>
Mon, 28 Aug 2006 11:59:07 +0000 (12:59 +0100)
committerkaf24@localhost.localdomain <kaf24@localhost.localdomain>
Mon, 28 Aug 2006 11:59:07 +0000 (12:59 +0100)
Windows zeroes out the UUID in the SMBIOS tables, but the identifier
is often needed by systems management code.  Duplicating the UUID
as the virtual system's serial number should help.

Signed-off-by: Andrew D. Ball <aball@us.ibm.com>
tools/firmware/hvmloader/smbios.c
tools/firmware/hvmloader/util.c
tools/firmware/hvmloader/util.h

index 64a84500ad1c71084e88834af0933f1c60bb1885..57618b2098d027d1dac2ead9ca4c5f763bad51f5 100644 (file)
@@ -116,8 +116,10 @@ smbios_table_size(uint32_t vcpus, const char *xen_version,
 
        /* type 0: "Xen", xen_version, and release_date */
        size += strlen("Xen") + strlen(xen_version) + 2;
-       /* type 1: "Xen", xen_version, "HVM domU" */
-       size += strlen("Xen") + strlen("HVM domU") + strlen(xen_version) + 3;
+       /* type 1: "Xen", xen_version, "HVM domU", UUID as string for 
+                   serial number */
+       size += strlen("Xen") + strlen("HVM domU") + strlen(xen_version) +
+                       36 + 4;
        /* type 3: "Xen" */
        size += strlen("Xen") + 1;
        /* type 4: socket designation ("CPU n"), processor_manufacturer */
@@ -371,6 +373,7 @@ static void *
 smbios_type_1_init(void *start, const char *xen_version, 
                   uint8_t uuid[16])
 {
+       char uuid_str[37];
        struct smbios_type_1 *p = (struct smbios_type_1 *)start;
        p->header.type = 1;
        p->header.length = sizeof(struct smbios_type_1);
@@ -379,7 +382,7 @@ smbios_type_1_init(void *start, const char *xen_version,
        p->manufacturer_str = 1;
        p->product_name_str = 2;
        p->version_str = 3;
-       p->serial_number_str = 0;
+       p->serial_number_str = 4;
     
        memcpy(p->uuid, uuid, 16);
 
@@ -395,6 +398,9 @@ smbios_type_1_init(void *start, const char *xen_version,
        start += strlen("HVM domU") + 1;
        strcpy((char *)start, xen_version);
        start += strlen(xen_version) + 1;
+       uuid_to_string(uuid_str, uuid); 
+       strcpy((char *)start, uuid_str);
+       start += strlen(uuid_str) + 1;
        *((uint8_t *)start) = 0;
     
        return start+1; 
index d23e5468594948bdb483c740b07a5dea7eaf533b..2ce5367fb93117b47dcc63d0fce2b16c30efccd9 100644 (file)
@@ -174,3 +174,57 @@ cpuid(uint32_t idx, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
                : "0" (idx) );
 }
 
+/* Write a two-character hex representation of 'byte' to digits[].
+   Pre-condition: sizeof(digits) >= 2 */
+void
+byte_to_hex(char *digits, uint8_t byte)
+{
+       uint8_t nybbel = byte >> 4;
+
+       if (nybbel > 9)
+               digits[0] = 'a' + nybbel-10;
+       else
+               digits[0] = '0' + nybbel;
+
+       nybbel = byte & 0x0f;
+       if (nybbel > 9)
+               digits[1] = 'a' + nybbel-10;
+       else
+               digits[1] = '0' + nybbel;
+}
+
+/* Convert an array of 16 unsigned bytes to a DCE/OSF formatted UUID
+   string.
+
+   Pre-condition: sizeof(dest) >= 37 */
+void
+uuid_to_string(char *dest, uint8_t *uuid)
+{
+       int i = 0;
+       char *p = dest;
+
+       for (i = 0; i < 4; ++i) {
+               byte_to_hex(p, uuid[i]);
+               p += 2;
+       }
+       *p++ = '-';
+       for (i = 4; i < 6; ++i) {
+               byte_to_hex(p, uuid[i]);
+               p += 2;
+       }
+       *p++ = '-';
+       for (i = 6; i < 8; ++i) {
+               byte_to_hex(p, uuid[i]);
+               p += 2;
+       }
+       *p++ = '-';
+       for (i = 8; i < 10; ++i) {
+               byte_to_hex(p, uuid[i]);
+               p += 2;
+       }
+       *p++ = '-';
+       for (i = 10; i < 16; ++i) {
+               byte_to_hex(p, uuid[i]);
+               p += 2;
+       }
+}
index 243c26c9798b76f5b24b2062bec3ab98fa3f88c0..5d21e8bc7f195deece0ba60acc9c65d701b6a1c1 100644 (file)
@@ -25,6 +25,16 @@ void *memcpy(void *dest, const void *src, unsigned n);
 void *memset(void *s, int c, unsigned n);
 char *itoa(char *a, unsigned int i);
 
+/* convert a byte to two lowercase hex digits, with no terminating NUL 
+   character.  digits[] must have at least two elements. */
+void byte_to_hex(char *digits, uint8_t byte);
+
+/* Convert an array of 16 unsigned bytes to a DCE/OSF formatted UUID
+   string.
+
+   Pre-condition: sizeof(dest) >= 37 */
+void uuid_to_string(char *dest, uint8_t *uuid);
+
 /* Debug output */
 void puts(const char *s);